<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/jquery-weui.min.css" />
    <link rel="stylesheet" type="text/css" href="../../css/index.css" />
    <link rel="stylesheet" type="text/css" href="../../css/order.css" />
    <title>订单</title>
    <script src="../../js/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery-weui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/baseConfig.js" type="text/javascript" charset="utf-8"></script>
</head>
<style type="text/css">
    .unfinishWork {
        color: #28C81E;
        border-right: 1px solid #e2e2e2;
    }
    
    .hasfinish {}
    
    .header-title b {
        width: 50%;
        float: left;
        box-sizing: border-box;
        font-size: 0.85rem;
        font-family: 'pfr';
        font-weight: normal;
    }
</style>

<body>
    <div id="header">
        <div class="header-title" style="position: fixed;top: 0;">
            <!--<span>订单</span>-->
            <b class='unfinishWork'>未完成</b>
            <b class="hasfinish">已完成</b>
        </div>
    </div>

    <div class="weui-search-bar" id="searchBar">
        <form class="weui-search-bar__form">
            <div class="weui-search-bar__box">
                <i class="weui-icon-search"></i>
                <input type="search" class="weui-search-bar__input" id="searchInput" disabled="disabled" placeholder="搜索" required="">
                <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
            </div>
            <label class="weui-search-bar__label" id="searchText">
				      <i class="weui-icon-search"></i>
				      <span>搜索</span>
				</label>
        </form>
        <!-- <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>-->
    </div>
    <div class="order-content">
        <ul class="order-list order-list1" style="display: block;">

        </ul>
        <ul class="order-list order-list2" style="display: none;">

        </ul>
    </div>
    <div class="weui-loadmore" style="margin-bottom: 2.5rem;">
        <i class="weui-loading"></i>
        <span class="weui-loadmore__tips">正在加载</span>
    </div>
    <div id="footer">
        <div class="weui-tabbar" style="position: fixed;">
            <!-- <a href="../demand/demand.html" data-info='1' class="weui-tabbar__item">
					<div class="weui-tabbar__icon">
						<img src="../../img/foot1.png" class="show" />
					</div>
					<p class="weui-tabbar__label">需求</p>
				</a>
				<a href="../information/information.html" data-info='2' class="weui-tabbar__item">
					<div class="weui-tabbar__icon">
						<img src="../../img/foot2.png" class="show" />
					</div>
					<p class="weui-tabbar__label">资讯</p>
				</a> -->
            <a href="../../index.html" data-info='6' class="weui-tabbar__item">
                <div class="weui-tabbar__icon">
                    <img src="../../img/foot6.png" class="show" />
                </div>
                <p class="weui-tabbar__label">首页</p>
            </a>
            <a href="applyPay.html" data-info='7' class="weui-tabbar__item">
                <div class="weui-tabbar__icon">
                    <img src="../../img/foot7.png" class="show" />
                </div>
                <p class="weui-tabbar__label">付款</p>
            </a>
            <a href="orderList.html" data-info='3' class="weui-tabbar__item weui-bar__item--on">
                <div class="weui-tabbar__icon">
                    <img src="../../img/footgreen3.png" class="show" />
                </div>
                <p class="weui-tabbar__label">订单</p>
            </a>
            <a href="../mine/mine.html" data-info='4' class="weui-tabbar__item">
                <div class="weui-tabbar__icon">
                    <img src="../../img/foot4.png" class="show" />
                </div>
                <p class="weui-tabbar__label">我的</p>
            </a>
        </div>
    </div>

</body>
<script type="text/javascript">
    $(document).ready(function() {
        $.showLoading("加载中...");
        $(function() {
                pageSize = 10, pageNumber = 1;
                //进入页面加载
                if (!localStorage.getItem("SupplierId")) {
                    $.confirm("尚未登录，是否去登录", function() {
                        //点击确认后的回调函数
                        window.location.href = "../login/login.html"
                    }, function() {
                        $.hideLoading();
                        //点击取消后的回调函数
                    });
                } else {
                    load(pageNumber, pageSize);
                }

                //滚动加载更多
                var loading = false;
                $(document.body).infinite().on("infinite", function() {
                    if (loading) {
                        return
                    }
                    loading = true;
                    setTimeout(function() {
                            pageNumber = pageNumber + 1;
                            load(pageNumber, pageSize)
                            loading = false
                        }, 1000) //模拟延迟
                })
            })
            //ajax加载数据
        function load(p, n) {
            $.ajax({
                type: "get",
                url: baseConfig.localHttp2 + "api/order/getOrderList",
                async: false,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                data: {
                    clientId: localStorage.getItem("SupplierId"),
                    pageNumber: p,
                    pageSize: n
                },
                success: function(data) {
                    $.hideLoading();
                    if (data.code == 100) {
                        var orderList = data.content.orderList
                        if (!orderList.length || orderList.length == data.content.totalCount) {
                            $(document.body).destroyInfinite()
                            $(".weui-loadmore").html('<div class="weui-loadmore weui-loadmore_line"> <span class="weui-loadmore__tips">暂无数据</span> </div>')
                        }
                        var li = ""
                        for (var i = 0; i < orderList.length; i++) {
                            if (orderList[i]["fgOrderStatus"] == 110) {

                            } else {
                                li += "<li status=" + orderList[i]["id"] + "><p class='first_p'>"
                                li += "<span>" + orderList[i]["orderNo"] + "</span>"
                                li += "</p>"
                                li += "<p class='second_p' style='margin-bottom: 0.85rem;'>"
                                if (!orderList[i]["materialCount"]) {
                                    li += "<span>" + 0 + "  吨</span></p>"
                                } else {
                                    li += "<span>" + orderList[i]["materialCount"] + "  吨</span></p>"
                                }

                                if (orderList[i]["orderSubmitTimeStr"] == null) {

                                } else {
                                    li += "<p class='third_p' style='margin-top: 0;'><span class='time'>" + orderList[i]["orderSubmitTimeStr"] + "</span></p>"
                                }

                                li += "<p class='four_p'><span class='statusColor' style='color:" + baseConfig.colorCode(orderList[i]["fgOrderStatus"]) + ";border-color:" + baseConfig.colorCode(orderList[i]["fgOrderStatus"]) + "'>" + orderList[i]["fgOrderStatusLabel"] + "</span></p>"
                                li += "<img src='../../img/right.png'/></li>"
                            }
                        }
                        $(".order-list1").append(li)
                    } else {
                        $.toptip(data.content, 1200, 'error');
                    }
                    $(".order-list li").on('click', function() {
                        var id = $(this).attr("status")
                        var statusColor = $(this).find(".statusColor").html()
                        if (statusColor == "待提交") {
                            location.href = "waitsubmitOrder.html?orderid=" + id
                        } else {
                            location.href = "orderInformation.html?orderid=" + id
                        }

                    })
                },
                error: function(data) {
                    $.hideLoading();
                }
            })
        }
        $(".unfinishWork").on("click", function() {
            $(".order-list2").hide()
            $(".order-list1").show()
            $(this).css("color", "#28C81E")
            $(".hasfinish").css("color", "#444")
        })
        $(".hasfinish").on("click", function() {
            $(this).css("color", "#28C81E")
            $.ajax({
                type: "get",
                url: baseConfig.localHttp2 + "api/order/getOrderList",
                async: false,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                },
                data: {
                    clientId: localStorage.getItem("SupplierId"),
                    pageNumber: 1,
                    pageSize: 100,
                },
                success: function(data) {
                    $.hideLoading();
                    if (data.code == 100) {
                        var orderList = data.content.orderList
                        if (!orderList.length || orderList.length == data.content.totalCount) {
                            $(document.body).destroyInfinite()
                            $(".weui-loadmore").html('<div class="weui-loadmore weui-loadmore_line"> <span class="weui-loadmore__tips">暂无数据</span> </div>')
                        }
                        var li2 = ""
                        for (var i = 0; i < orderList.length; i++) {
                            if (orderList[i]["fgOrderStatus"] == 110) {

                                li2 += "<li status=" + orderList[i]["id"] + "><p class='first_p'>"
                                li2 += "<span>" + orderList[i]["orderNo"] + "</span>"
                                li2 += "</p>"
                                li2 += "<p class='second_p' style='margin-bottom: 0.85rem;'>"
                                if (!orderList[i]["materialCount"]) {
                                    li2 += "<span>" + 0 + "  吨</span></p>"
                                } else {
                                    li2 += "<span>" + orderList[i]["materialCount"] + "  吨</span></p>"
                                }

                                if (orderList[i]["orderSubmitTimeStr"] == null) {

                                } else {
                                    li2 += "<p class='third_p' style='margin-top: 0;'><span class='time'>" + orderList[i]["orderSubmitTimeStr"] + "</span></p>"
                                }

                                li2 += "<p class='four_p'><span class='statusColor' style='color:" + baseConfig.colorCode(orderList[i]["fgOrderStatus"]) + ";border-color:" + baseConfig.colorCode(orderList[i]["fgOrderStatus"]) + "'>" + orderList[i]["fgOrderStatusLabel"] + "</span></p>"
                                li2 += "<img src='../../img/right.png'/></li>"
                            } else {

                            }
                        }
                        $(".order-list2").empty()
                        $(".order-list2").append(li2)

                    } else {
                        $.toptip(data.content, 1200, 'error');
                    }
                    $(".order-list li").on('click', function() {
                        var id = $(this).attr("status")
                        var statusColor = $(this).find(".statusColor").html()
                        if (statusColor == "待提交") {
                            location.href = "waitsubmitOrder.html?orderid=" + id
                        } else {
                            location.href = "orderInformation.html?orderid=" + id
                        }

                    })
                },
                error: function(data) {
                    $.hideLoading();
                }
            })
            $(".unfinishWork").css("color", "#444")
            $(".order-list2").show()
            $(".order-list1").hide()
        })

        //点击搜索跳到搜索页面
        $(".weui-search-bar__box").on("click", function() {
            location.href = "../../html/common/orderSearch.html"
        })
    })
</script>

</html>
<li>